package kandl.automation.steprunner.selenium.commands;


import kandl.automation.steprunner.selenium.Command;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.springframework.stereotype.Component;

@Component
class VerifyText implements Command {
    @Override
    public void runCommand(WebDriver driver, String... params) throws Exception {

        WebElement webElement =  driver.findElement(By.xpath(params[0]));

        if (webElement.isDisplayed()) {
            if(!webElement.getText().equals(params[1])) {
                throw new VerificationFailedException("Parameters " + params[0] + " and " + params[1] +" are not the same.");
            }
        }
        else {
            throw new WebElementNotFoundException("Xpath "+ params[0] + " is not found.");
        }
    }

    @Override
    public String getName() {
        return "verify_text";
    }
}
